<?php

/**
 * This is the model class for table "{{message}}".
 *
 * The followings are the available columns in table '{{message}}':
 * @property integer $id
 * @property integer $pid
 * @property integer $post_uid
 * @property integer $to_uid
 * @property string $content
 * @property integer $status
 * @property integer $c_delete
 * @property integer $c_replay
 * @property integer $open
 * @property string $title
 * @property integer $view
 * @property string $time
 */
class Message extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Message the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{message}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pid, post_uid, to_uid, status, time', 'required'),
			array('pid, post_uid, to_uid, status, c_delete, c_replay, open, view', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, pid, post_uid, to_uid, content, status, c_delete, c_replay, open, title, view, time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
            'post_user'=>array(self::BELONGS_TO, 'Profiles', 'post_uid'),
            'to_user'=>array(self::BELONGS_TO, 'Profiles', 'to_uid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'pid' => 'Pid',
			'post_uid' => 'Post Uid',
			'to_uid' => 'To Uid',
			'content' => 'Content',
			'status' => 'Status',
			'c_delete' => 'C Delete',
			'c_replay' => 'C Replay',
			'open' => 'Open',
			'title' => 'Title',
			'view' => 'View',
			'time' => 'Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('pid',$this->pid);
		$criteria->compare('post_uid',$this->post_uid);
		$criteria->compare('to_uid',$this->to_uid);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('c_delete',$this->c_delete);
		$criteria->compare('c_replay',$this->c_replay);
		$criteria->compare('open',$this->open);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('view',$this->view);
		$criteria->compare('time',$this->time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}